package org.lejos.example;

// MotorEx2.java
// Show use of motor count
// Must move 100 counts each time

import gin.and.tonic.*;
import lejos.nxt.Button;

public class MotorEx2
{
  MotorEx2()
  {
    NxtRobot robot = new NxtRobot();
    Motor mot = new Motor(MotorPort.A);
    robot.addPart(mot);
    mot.setSpeed(5);

    mot.rotateTo(100);
    System.out.println("Count: " + mot.getMotorCount()); // 100
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.rotateTo(100);
    System.out.println("Count: " + mot.getMotorCount()); // 100
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.continueRelativeTo(100);
    System.out.println("Count: " + mot.getMotorCount()); // 200
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.continueTo(300);
    System.out.println("Count: " + mot.getMotorCount()); // 300
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.continueRelativeTo(-100);
    System.out.println("Count: " + mot.getMotorCount()); // 200
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.continueTo(100);
    System.out.println("Count: " + mot.getMotorCount());  // 100
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    mot.rotateTo(-100);
    System.out.println("Count: " + mot.getMotorCount()); // -100
    System.out.println("ENTER to cont");
    while (!Button.ENTER.isPressed())
    {}

    robot.exit();
  }

  public static void main(String[] args)
  {
    new MotorEx2();
  }
}
